//
//  ViewController.m
//  YiChat
//
//  Created by Hesilen on 16/7/7.
//  Copyright © 2016年 Hesilen. All rights reserved.
//

#import "ViewController.h"

#import "LoginViewController.h"

#import "FileViewController.h"

#import "PersonViewController.h"

#import "NewsViewController.h"

#import "HomeViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    

    [self performSelector:@selector(animation) withObject:nil afterDelay:0.5];
    
}

-(void)animation
{
    NSLog(@"-----%d",[self isNeedLogin]);
    if ([self isNeedLogin]) {
        LoginViewController *loginVC = [[LoginViewController alloc]init];
        UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:loginVC];
        WINDOW.rootViewController = nav;
        
    }else{
        
        HomeViewController *homeVC = [[HomeViewController alloc]init];
        UINavigationController *nav1 = [[UINavigationController alloc]initWithRootViewController:homeVC];
        homeVC.tabBarItem.title = @"主页";
        homeVC.tabBarItem.image = [UIImage imageNamed:@"main"];
        
        NewsViewController *newsVC = [[NewsViewController alloc]init];
        UINavigationController *nav2 = [[UINavigationController alloc]initWithRootViewController:newsVC];
        newsVC.tabBarItem.title = @"新闻";
        newsVC.tabBarItem.image = [UIImage imageNamed:@"news"];
        
        FileViewController *fileVC = [[FileViewController alloc]init];
        UINavigationController *nav3 = [[UINavigationController alloc]initWithRootViewController:fileVC];
        fileVC.tabBarItem.title = @"文件";
        fileVC.tabBarItem.image = [UIImage imageNamed:@"file"];
        
        PersonViewController *personVC = [[PersonViewController alloc]init];
        UINavigationController *nav4 = [[UINavigationController alloc]initWithRootViewController:personVC];
        personVC.tabBarItem.title = @"个人";
        personVC.tabBarItem.image = [UIImage imageNamed:@"person"];
        
        UITabBarController *tabbar = [[UITabBarController alloc]init];
        tabbar.viewControllers = @[nav1,nav2,nav3,nav4];
        
        WINDOW.rootViewController = tabbar;
        
    }
    [UIView animateWithDuration:0.5 animations:^{
        [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:WINDOW cache:YES];
    }];
}

-(BOOL)isNeedLogin
{
    NSDate *currentDate = [NSDate date];
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    NSDate *loseDate = [userDefaults objectForKey:@"lose_time"];
    if (loseDate == nil || [currentDate compare:loseDate] == NSOrderedDescending)
    {
        return YES;
    }
    
    return NO;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
